package com.ins1st.plus.base;

import java.io.Serializable;
import java.util.List;

/**
 * @program: ins1st-plus
 * @description: 业务层返回结果
 * @author: coderSun
 * @create: 2019-09-09 09:01
 **/
public class ServiceResult implements Serializable {

    private boolean success;
    private int code;
    private String message;
    private Object obj;
    private List<?> data;

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getObj() {
        return obj;
    }

    public void setObj(Object obj) {
        this.obj = obj;
    }

    public List<?> getData() {
        return data;
    }

    public void setData(List<?> data) {
        this.data = data;
    }

    /**
     * 返回结果  文字
     *
     * @return
     */
    public static ServiceResult success() {
        ServiceResult serviceResult = new ServiceResult();
        serviceResult.setSuccess(true);
        serviceResult.setCode(200);
        serviceResult.setMessage("请求成功");
        return serviceResult;
    }

    /**
     * 返回结果 文字
     *
     * @param message
     * @return
     */
    public static ServiceResult success(String message) {
        ServiceResult serviceResult = new ServiceResult();
        serviceResult.setSuccess(true);
        serviceResult.setCode(200);
        serviceResult.setMessage(message);
        return serviceResult;
    }

    /**
     * 返回结果 单个数据
     *
     * @param obj
     * @return
     */
    public static ServiceResult success(Object obj) {
        ServiceResult serviceResult = new ServiceResult();
        serviceResult.setSuccess(true);
        serviceResult.setCode(200);
        serviceResult.setObj(obj);
        return serviceResult;
    }

    /**
     * 返回结果  集合
     *
     * @param list
     * @return
     */
    public static ServiceResult success(List<?> list) {
        ServiceResult serviceResult = new ServiceResult();
        serviceResult.setSuccess(true);
        serviceResult.setCode(200);
        serviceResult.setData(list);
        return serviceResult;
    }

    /**
     * 返回结果  文字
     *
     * @param message
     * @return
     */
    public static ServiceResult error(String message) {
        ServiceResult serviceResult = new ServiceResult();
        serviceResult.setSuccess(false);
        serviceResult.setCode(200);
        serviceResult.setMessage(message);
        return serviceResult;
    }

}
